import {ListPage} from "custom/index";
import {getCustomerBenefitInquiry} from './api'
import LinkColumn from '@/components/table-column/LinkColumn.vue'
import lossDialog from './dialog'
import dayjs from 'dayjs'
import CustomerBenefitInquiryTableBefore from './custom/TableBefore'
import TableBefore from './components/TableBefore.vue'
import ColumnTotal from './components/ColumnTotal.vue'

const tableBefore = new CustomerBenefitInquiryTableBefore('CustomerBenefitInquiryTableBefore')
tableBefore.setComponent(TableBefore)

const spanMethod = ({row, column}) => {
	if (column.property === 'customerNo' || column.property === 'customerName' || column.property === 'total' || column.property === '_index' || column.property === '_action') {
		return {
			rowspan: row.rowspan,
			colspan: row.colspan
		}
	}
}

const page = new ListPage('CustomerBenefitInquiry');

page
	.api(getCustomerBenefitInquiry)
	.useSearch()
		.addInputItem('keyword', '客户名称/客户ID/店铺ID/店铺名称')
		.addItem({prop: 'customerNo', label: '客户ID'})
		.addItem({prop: 'customerName', label: '客户名称'})
		.addItem({prop: 'shopNo', label: '店铺ID'})
		.addItem({prop: 'shopName', label: '店铺名称'})
		// .addDateRangePicker(['firstStartDateStart', 'firstStartDateEnd'], { label: '日期' })
		.addDatePicker({
			prop: 'month',
			label: '月份',
			type: 'month',
			format: "YYYY-MM",
			valueFormat: "YYYY-MM",
			clearable: false,
			default: dayjs().format('YYYY-MM')
		})
		.end()
	.useTable()
		.setProp('spanMethod', spanMethod)
		.useColumn({prop: '_index', label: '#', align: 'center', width: 50, fixed: 'left'}).end()
		.useColumn('customerName').label('客户名称').minWidth(140).end()
		.useCustomColumn(ColumnTotal, 'total').label('合计').minWidth(360).showOverflowTooltip(false).end()
		.useCustomColumn(LinkColumn, {
				prop: 'shopName',
				linkProp: 'shopLinkUrl',
				linkType: 'link'
		}).label('店铺名称').minWidth(140).end()
		// .useColumn('cooperateDays').label('合作天数').minWidth(120).end()
		.useColumn('workDays').label('工作天数').minWidth(140).end()
		// .useColumn('dayReceptionVolume').label('日均咨询量').minWidth(120).end()
		.useColumn('baseSalary').label('店铺底薪').align('center').minWidth(140).end()
		.useColumn('commissionSalary').label('提成效益（元）').align('center').minWidth(140).end()
	
		.useColumn('sumSalary').label('效益合计（元）').align('center').minWidth(140).end()
		.useColumn('dayReceptionVolume').label('日均接待量').minWidth(140).end()
		.useColumn('monthSalary').label('月效益值预估').minWidth(140).end()
		.end()
	.usePagination()
	.end()
	.useAuthButton()
	.useItem('export').content('导出数据').exportExcel().end()
	.end()
	.useAuthColumn()
	.useItem('').content('详情').editRow(lossDialog).end()
	.end()
	.addChild(tableBefore, 'table-before')

export default page
